﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test.UI
{
    public partial class Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["Id"]);
                var info = BLL.ClassInfoBLL.Select(id);
                if (info != null)
                {
                    Text1.Value = info.Id + "";
                    TextBox1.Text = info.Name;
                    TextBox2.Text = info.Comment;
                }
                else
                {
                    Response.Redirect("~/ClassInfo.aspx");
                }
            }
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Model.ClassInfo info = new Model.ClassInfo()
            {
                Id = Convert.ToInt32(Text1.Value),
                Comment = TextBox2.Text,
                Name = TextBox1.Text
            };
            if (BLL.ClassInfoBLL.Update(info) > 0)
            {
                Response.Write("<script>alert('修改成功！');location='ClassInfo.aspx';</script>");
            }
        }
    }
}